package com.party.course.eumn;

import java.lang.reflect.Field;
import java.math.BigDecimal;

/**
 * 分账实现
 */
public enum SubAmount {
    // 小学、168：老师50（正课完成）、老师20（复习课消课完成）、交付中心15、交付中心组长5、合伙人53、软件10、公司10

    c1_amont(0, 0, 9, 9, new BigDecimal(168)),


    c1_coach(0, 0, 1, 1, new BigDecimal(50)),
    c1_coach_per(0, 0, 1, 0, new BigDecimal(20)),
    c1_payCenter(0, 0, 0, 1, new BigDecimal(15)),
    c1_unitMan1(0, 0, 6, 1, new BigDecimal(5)),
    c1_unitJLB(0, 0, 7, 1, new BigDecimal(5)),
    c1_partner(0, 0, 3, 0, new BigDecimal(53)),
    c1_app(0, 0, 4, 1, new BigDecimal(10)),
    c1_company(0, 0, 5, 1, new BigDecimal(10)),

    // 小学、188：老师50（正课完成）、老师20（复习课完成）、交付中心15、交付中心组长5、合伙人73、软件10、公司10

    c1__c_amont(0, 1, 9, 9, new BigDecimal(188)),

    c1_c_coach(0, 1, 1, 1, new BigDecimal(50)),
    c1_c_coach_per(0, 1, 1, 0, new BigDecimal(20)),
    c1_c_payCenter(0, 1, 0, 1, new BigDecimal(15)),
    c1_c_unitMan1(0, 1, 6, 1, new BigDecimal(5)),
    c1_c_unitJLB(0, 1, 7, 1, new BigDecimal(5)),
    c1_c_partner(0, 1, 3, 0, new BigDecimal(73)),
    c1_c_app(0, 1, 4, 1, new BigDecimal(10)),
    c1_c_company(0, 1, 5, 1, new BigDecimal(10)),

    // 初中、208：老师60（正课完成）、老师30（复习课完成）、交付中心15、交付中心组长5、合伙人73、软件10、公司10

    c2_amont(1, 0, 9, 9, new BigDecimal(208)),

    c2_coach(1, 0, 1, 1, new BigDecimal(60)),
    c2_coach_per(1, 0, 1, 0, new BigDecimal(30)),
    c2_payCenter(1, 0, 0, 1, new BigDecimal(15)),
    c2_unitMan1(1, 0, 6, 1, new BigDecimal(5)),
    c2_unitJLB(1, 0, 7, 1, new BigDecimal(5)),

    c2_partner(1, 0, 3, 0, new BigDecimal(73)),
    c2_app(1, 0, 4, 1, new BigDecimal(10)),
    c2_company(1, 0, 5, 1, new BigDecimal(10)),

    // 初中、228：老师60（正课完成）、老师30（复习课完成）、交付中心15、交付中心组长5、合伙人93、软件10、公司10

    c2_c_amont(1, 1, 9, 9, new BigDecimal(228)),



    c2_c_coach(1, 1, 1, 1, new BigDecimal(60)),
    c2_c_coach_per(1, 1, 1, 0, new BigDecimal(30)),
    c2_c_payCenter(1, 1, 0, 1, new BigDecimal(15)),
    c2_c_unitMan1(1, 1, 6, 1, new BigDecimal(5)),
    c2_c_unitJLB(1, 1, 7, 1, new BigDecimal(5)),
    c2_c_partner(1, 1, 3, 0, new BigDecimal(93)),
    c2_c_app(1, 1, 4, 1, new BigDecimal(10)),
    c2_c_company(1, 1, 5, 1, new BigDecimal(10)),

    // 高中、268：老师70（正课完成）、老师40（复习课完成）、交付中心15、交付中心组长5、合伙人113、软件10、公司10

    c3_amont(2, 0, 9, 9, new BigDecimal(268)),

    c3_coach(2, 0, 1, 1, new BigDecimal(70)),
    c3_coach_per(2, 0, 1, 0, new BigDecimal(40)),
    c3_payCenter(2, 0, 0, 1, new BigDecimal(15)),
    c3_unitMan1(2, 0, 6, 1, new BigDecimal(5)),
    c3_unitJLB(2, 0, 7, 1, new BigDecimal(5)),
    c3_partner(2, 0, 3, 0, new BigDecimal(113)),
    c3_app(2, 0, 4, 1, new BigDecimal(10)),
    c3_company(2, 0, 5, 1, new BigDecimal(10)),

    // 高中、288：老师70（正课完成）、老师40（复习课完成）、交付中心15、交付中心组长5、合伙人133、软件10、公司10

    c3_c_amont(2, 1, 9, 9, new BigDecimal(288)),



    c3_c_coach(2, 1, 1, 1, new BigDecimal(70)),
    c3_c_coach_per(2, 1, 1, 0, new BigDecimal(40)),
    c3_c_payCenter(2, 1, 0, 1, new BigDecimal(15)),
    c3_c_unitMan1(2, 1, 6, 1, new BigDecimal(5)),
    c3_c_unitJLB(2, 1, 7, 1, new BigDecimal(5)),
    c3_c_partner(2, 1, 3, 0, new BigDecimal(133)),
    c3_c_app(2, 1, 4, 1, new BigDecimal(10)),
    c3_c_company(2, 1, 5, 1, new BigDecimal(10)),

    ;
    /**
     * 0小学，1初中，2高中
     */
    private int section = 0;
    /**
     * 0一级168，1二级188
     */
    private int level = 0;
    /**
     * 0交付中心，1教练，2学管，3合伙人，4软件，5公司  6 交付中心组长
     */
    private int role = 0;
    /**
     * 是否是销售或复习课: 0是 1否
     */
    private int isSales = 0;
    /**
     * 金额
     */
    private BigDecimal amount = BigDecimal.ZERO;
    /**
     * 金额
     */
    private BigDecimal perAmount = BigDecimal.ZERO;

    SubAmount() {
    }

    SubAmount(int section, int level, int role, int isSales, BigDecimal amount, BigDecimal perAmount) {
        this.section = section;
        this.level = level;
        this.role = role;
        this.isSales = isSales;
        this.amount = amount;
        this.perAmount = perAmount;
    }

    SubAmount(int section, int level, int role, int isSales, BigDecimal amount) {
        this.section = section;
        this.level = level;
        this.role = role;
        this.isSales = isSales;
        this.amount = amount;
    }

    public int getSection() {
        return section;
    }

    public int getLevel() {
        return level;
    }

    public int getRole() {
        return role;
    }

    public BigDecimal getAmount() {
        return amount;
    }

    public int getIsSales() {
        return isSales;
    }

    public void setAmount(BigDecimal amount) {
        this.amount = amount;
    }

    public BigDecimal getPerAmount() {
        return perAmount;
    }

    public static BigDecimal getAmountByCondition(int section, int level, int role, int isSales) {
        // 遍历SubAmount枚举类
        for (SubAmount subAmount : SubAmount.values()) {
            // 判断传入的参数是否与枚举类中的值相等
            if (subAmount.getSection() == section && subAmount.getLevel() == level && subAmount.getRole() == role && subAmount.getIsSales() == isSales) {
                // 获取枚举类中的amount字段
                Field field = null;
                try {
                    field = subAmount.getClass().getDeclaredField("amount");
                    // 设置字段可访问
                    field.setAccessible(true);
                    // 返回字段值
                    return (BigDecimal) field.get(subAmount);
                } catch (Exception e) {
                    // 打印异常信息
                    e.printStackTrace();
                    // 抛出运行时异常
                    throw new RuntimeException(e.getMessage());
                }
            }
        }
        // 如果没有匹配的枚举类，则返回0
        return BigDecimal.ZERO;
    }

    public static BigDecimal getPerAmountByCondition(int section, int level, int role, int isSales) {
        // 遍历SubAmount枚举类
        for (SubAmountOld subAmount : SubAmountOld.values()) {
            // 判断传入的参数是否与枚举类中的值相等
            if (subAmount.getAmount().compareTo(BigDecimal.ZERO) == 0 && subAmount.getSection() == section && subAmount.getLevel() == level && subAmount.getRole() == role && subAmount.getIsSales() == isSales) {
                // 获取枚举类中的amount字段
                Field field = null;
                try {
                    field = subAmount.getClass().getDeclaredField("perAmount");
                    // 设置字段可访问
                    field.setAccessible(true);
                    // 返回字段值
                    return (BigDecimal) field.get(subAmount);
                } catch (Exception e) {
                    // 打印异常信息
                    e.printStackTrace();
                    // 抛出运行时异常
                    throw new RuntimeException(e.getMessage());
                }
            }
        }
        // 如果没有匹配的枚举类，则返回0
        return BigDecimal.ZERO;
    }

    public static void main(String[] args) {
        BigDecimal decimal = SubAmountOld.getAmountByCondition(0, 0, 1, 0);
        System.out.println(decimal.toString());
    }
}
